package com.his.outpatientvisit.service.impl;

import com.his.login.entity.DictEmployee;
import com.his.outpatientvisit.dao.PatiOutVisitSettlePaylistMapper;
import com.his.outpatientvisit.entity.PatiOutVisitSettlePaylist;
import com.his.outpatientvisit.service.PatiOutVisitSettlePaylistService;
import com.his.outpatientvisit.vo.PatiOutVisitSettlePaylistVo;
import com.xiao.common.util.BeanUtil;
import com.xiao.common.util.WorkIdUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PatiOutVisitSettlePaylistServiceImpl implements PatiOutVisitSettlePaylistService {
    @Resource
    private PatiOutVisitSettlePaylistMapper patiOutVisitSettlePaylistMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertPatiOutVisitSettlePayList(DictEmployee employee, PatiOutVisitSettlePaylistVo patiOutVisitSettlePaylistVo) throws Exception{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date today = new Date();
        PatiOutVisitSettlePaylist patiOutVisitSettlePaylist = BeanUtil.copyBean(patiOutVisitSettlePaylistVo, PatiOutVisitSettlePaylist.class);
        String empid = employee.getEMPID();
        String hospid = employee.getHOSPID();
        Date insertdate = simpleDateFormat.parse(simpleDateFormat.format(today));

        String payId = WorkIdUtil.nextId();
        patiOutVisitSettlePaylist.setEmpid(empid);
        patiOutVisitSettlePaylist.setIoflag(new BigDecimal(1));
        patiOutVisitSettlePaylist.setHospid(hospid);
        patiOutVisitSettlePaylist.setCreatetime(insertdate);
        patiOutVisitSettlePaylist.setPayid(payId);

        patiOutVisitSettlePaylistMapper.settlepaylist_add(patiOutVisitSettlePaylist);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updatePatiOutVisitSettlePayList(DictEmployee employee, PatiOutVisitSettlePaylistVo patiOutVisitSettlePaylistVo)  throws Exception{
        PatiOutVisitSettlePaylist patiOutVisitSettlePaylist = BeanUtil.copyBean(patiOutVisitSettlePaylistVo, PatiOutVisitSettlePaylist.class);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date today = new Date();
        Date insertdate = simpleDateFormat.parse(simpleDateFormat.format(today));

        String payId = WorkIdUtil.nextId();
        patiOutVisitSettlePaylist.setPayid(payId);
        patiOutVisitSettlePaylist.setIoflag(new BigDecimal(-1));
        patiOutVisitSettlePaylist.setCreatetime(insertdate);
        patiOutVisitSettlePaylist.setOutpayid(patiOutVisitSettlePaylistVo.getOutpayid());
        patiOutVisitSettlePaylist.setEmpid(employee.getEMPID());

        patiOutVisitSettlePaylistMapper.settlepaylist_add(patiOutVisitSettlePaylist);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<PatiOutVisitSettlePaylist> selectPatiOutVisitSettlePayList(String patiId, String settleId) {
        return patiOutVisitSettlePaylistMapper.settlepaylist_select(patiId,settleId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cancPatiOutVisitSettlePayList(DictEmployee employee, PatiOutVisitSettlePaylistVo patiOutVisitSettlePaylistVo) throws Exception {

    }
}
